package com.social.socialservice.idal;

import com.social.socialservice.model.UserInfo;
import com.social.socialservice.unit.Pager;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 关注用户接口方法定义
 */
@Mapper
@Component
public interface IFansDAL {
    /**
     * 根据用户id查询关注者(粉丝)分页数据
     */
    @Select("SELECT ex_user.user_id,ex_user.username,ex_user.user_nickname,ex_user.user_headimg,ex_user.user_bgimg,\n" +
            "ex_user.user_info,ex_user.auth_id,ex_fanslist.* FROM ex_user,ex_fanslist\n" +
            "WHERE\n" +
            "ex_user.user_id = ex_fanslist.fans_fo_id\n" +
            "AND\n" +
            "ex_fanslist.fo_id = #{user_id}\n" +
            "ORDER BY ex_fanslist.fo_time DESC\n" +
            "LIMIT #{startIndex},#{pageSize};")
    public List<UserInfo> getFoUserListMapperByUserId(Pager pager);

    /**
     * 根据用户id查询关注者（粉丝）分页counts
     */
    @Select("SELECT count(*) FROM ex_user,ex_fanslist\n" +
            "WHERE\n" +
            "ex_user.user_id = ex_fanslist.fans_fo_id\n" +
            "AND\n" +
            "ex_fanslist.fo_id = #{user_id};")
    public Integer getFoUserListMapperCountsByUserId(Pager pager);

    /**
     * 根据用户id查询其粉丝的用户分页数据
     */
    @Select("SELECT ex_user.user_id,ex_user.username,ex_user.user_nickname,ex_user.user_headimg,ex_user.user_bgimg,\n" +
            "ex_user.user_info,ex_user.auth_id,ex_fanslist.* FROM ex_user,ex_fanslist\n" +
            "WHERE\n" +
            "ex_user.user_id = ex_fanslist.fo_id\n" +
            "AND\n" +
            "ex_fanslist.fans_fo_id = #{user_id}\n" +
            "ORDER BY ex_fanslist.fo_time DESC\n" +
            "LIMIT #{startIndex},#{pageSize};")
    public List<UserInfo> getFansUserListMapperByUserId(Pager pager);

    /**
     * 根据用户id查询其粉丝的用户分页数据counts
     */
    @Select("SELECT count(*) FROM ex_user,ex_fanslist\n" +
            "WHERE\n" +
            "ex_user.user_id = ex_fanslist.fo_id\n" +
            "AND\n" +
            "ex_fanslist.fans_fo_id = #{user_id};")
    public Integer getFansUserListMapperCountsByUserId(Pager pager);


    /**
     * 已经认证的粉丝用户列表分页数据
     */
    @Select("SELECT ex_user.user_id,ex_user.username,ex_user.user_nickname,ex_user.user_headimg,ex_user.user_bgimg,\n" +
            "ex_user.user_info,ex_user.auth_id,ex_fanslist.* FROM ex_user,ex_fanslist\n" +
            "WHERE\n" +
            "ex_user.user_id = ex_fanslist.fo_id\n" +
            "AND\n" +
            "ex_user.auth_id>0\n" +
            "AND\n" +
            "ex_fanslist.fans_fo_id = #{user_id}\n" +
            "ORDER BY ex_fanslist.fo_time DESC\n" +
            "LIMIT #{startIndex},#{pageSize};")
    public List<UserInfo> getAuthFansUserListMapperByUserId(Pager pager);

    /**
     * 已经认证的粉丝用户列表
     * 数据总数
     */
    @Select("SELECT count(*) FROM ex_user,ex_fanslist\n" +
            "WHERE\n" +
            "ex_user.user_id = ex_fanslist.fo_id\n" +
            "AND\n" +
            "ex_user.auth_id>0\n" +
            "AND\n" +
            "ex_fanslist.fans_fo_id = #{user_id};")
    public Integer getAuthFansUserListMapperCountsByUserId(Pager pager);


    /**
     * 你认识的人：他关注的人，你也关注了
     * 通过用户id查询你认识的人
     * 参数：需要你要查询用户的id和当前用户id
     */
    @Select("SELECT t1.* FROM \n" +
            "(SELECT ex_user.user_id,ex_user.username,ex_user.user_nickname,ex_user.user_headimg,ex_user.user_bgimg,\n" +
            "ex_user.user_info,ex_user.auth_id,ex_fanslist.* from ex_user,ex_fanslist\n" +
            "WHERE\n" +
            "ex_user.user_id = ex_fanslist.fans_fo_id\n" +
            "AND\n" +
            "ex_fanslist.fo_id = #{current_user_id}) t1\n" +
            "where t1.user_id in (SELECT ex_user.user_id from ex_user,ex_fanslist\n" +
            "WHERE\n" +
            "ex_user.user_id = ex_fanslist.fans_fo_id\n" +
            "AND\n" +
            "ex_fanslist.fo_id = #{user_id})\n" +
            "ORDER BY t1.fo_time DESC\n" +
            "LIMIT #{startIndex},#{pageSize};")
    public List<UserInfo> getYouKnowFoUserListMapperByUserId(Pager pager);

    /**
     * 你认识的人：他关注的人，你也关注了
     * 通过用户id查询你认识的人 数据总数
     * 参数：需要你要查询用户的id和当前用户id
     */
    @Select("SELECT count(*) FROM \n" +
            "(SELECT ex_user.user_id,ex_user.username,ex_user.user_nickname,ex_user.user_headimg,ex_user.user_bgimg,\n" +
            "ex_user.user_info,ex_user.auth_id,ex_fanslist.* from ex_user,ex_fanslist\n" +
            "WHERE\n" +
            "ex_user.user_id = ex_fanslist.fans_fo_id\n" +
            "AND\n" +
            "ex_fanslist.fo_id = #{current_user_id}) t1\n" +
            "where t1.user_id in (SELECT ex_user.user_id from ex_user,ex_fanslist\n" +
            "WHERE\n" +
            "ex_user.user_id = ex_fanslist.fans_fo_id\n" +
            "AND\n" +
            "ex_fanslist.fo_id = #{user_id});")
    public Integer getYouKnowFoUserListMapperCountsByUserId(Pager pager);

}
